from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-01-23 14:28:25.147713
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 23, Jan, 2021
Time: 14:28:29
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.4051
Nobs: 180.000 HQIC: -46.3543
Log likelihood: 2021.46 FPE: 3.87180e-21
AIC: -47.0016 Det(Omega_mle): 2.38003e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.437423 0.144150 3.034 0.002
L1.Burgenland 0.131620 0.075829 1.736 0.083
L1.Kärnten -0.234052 0.061601 -3.799 0.000
L1.Niederösterreich 0.132392 0.174222 0.760 0.447
L1.Oberösterreich 0.224796 0.149970 1.499 0.134
L1.Salzburg 0.184638 0.079667 2.318 0.020
L1.Steiermark 0.096368 0.107893 0.893 0.372
L1.Tirol 0.155309 0.072186 2.151 0.031
L1.Vorarlberg -0.004284 0.067203 -0.064 0.949
L1.Wien -0.110414 0.144581 -0.764 0.445
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.508011 0.183689 2.766 0.006
L1.Burgenland 0.014793 0.096628 0.153 0.878
L1.Kärnten 0.371081 0.078497 4.727 0.000
L1.Niederösterreich 0.102456 0.222009 0.461 0.644
L1.Oberösterreich -0.165814 0.191105 -0.868 0.386
L1.Salzburg 0.185662 0.101519 1.829 0.067
L1.Steiermark 0.252595 0.137486 1.837 0.066
L1.Tirol 0.139994 0.091986 1.522 0.128
L1.Vorarlberg 0.178289 0.085637 2.082 0.037
L1.Wien -0.574182 0.184237 -3.117 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.303722 0.064715 4.693 0.000
L1.Burgenland 0.112474 0.034043 3.304 0.001
L1.Kärnten -0.025287 0.027655 -0.914 0.361
L1.Niederösterreich 0.050132 0.078215 0.641 0.522
L1.Oberösterreich 0.284443 0.067328 4.225 0.000
L1.Salzburg 0.004945 0.035766 0.138 0.890
L1.Steiermark -0.019015 0.048438 -0.393 0.695
L1.Tirol 0.094863 0.032408 2.927 0.003
L1.Vorarlberg 0.115324 0.030170 3.822 0.000
L1.Wien 0.084143 0.064908 1.296 0.195
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.211604 0.075074 2.819 0.005
L1.Burgenland -0.007509 0.039492 -0.190 0.849
L1.Kärnten 0.023762 0.032082 0.741 0.459
L1.Niederösterreich 0.028406 0.090736 0.313 0.754
L1.Oberösterreich 0.387789 0.078105 4.965 0.000
L1.Salzburg 0.095683 0.041491 2.306 0.021
L1.Steiermark 0.185573 0.056191 3.303 0.001
L1.Tirol 0.044658 0.037595 1.188 0.235
L1.Vorarlberg 0.091725 0.035000 2.621 0.009
L1.Wien -0.064068 0.075298 -0.851 0.395
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.549554 0.148997 3.688 0.000
L1.Burgenland 0.074178 0.078378 0.946 0.344
L1.Kärnten 0.005699 0.063672 0.090 0.929
L1.Niederösterreich -0.031837 0.180080 -0.177 0.860
L1.Oberösterreich 0.133893 0.155013 0.864 0.388
L1.Salzburg 0.051455 0.082346 0.625 0.532
L1.Steiermark 0.123507 0.111520 1.107 0.268
L1.Tirol 0.222295 0.074614 2.979 0.003
L1.Vorarlberg 0.012644 0.069463 0.182 0.856
L1.Wien -0.127695 0.149442 -0.854 0.393
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.156784 0.106228 1.476 0.140
L1.Burgenland -0.020791 0.055880 -0.372 0.710
L1.Kärnten -0.013366 0.045395 -0.294 0.768
L1.Niederösterreich 0.142798 0.128388 1.112 0.266
L1.Oberösterreich 0.386428 0.110517 3.497 0.000
L1.Salzburg -0.025558 0.058709 -0.435 0.663
L1.Steiermark -0.035763 0.079509 -0.450 0.653
L1.Tirol 0.189374 0.053196 3.560 0.000
L1.Vorarlberg 0.043365 0.049524 0.876 0.381
L1.Wien 0.183527 0.106545 1.723 0.085
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.238901 0.134926 1.771 0.077
L1.Burgenland 0.073323 0.070977 1.033 0.302
L1.Kärnten -0.052688 0.057659 -0.914 0.361
L1.Niederösterreich -0.057207 0.163074 -0.351 0.726
L1.Oberösterreich -0.088105 0.140374 -0.628 0.530
L1.Salzburg 0.034028 0.074569 0.456 0.648
L1.Steiermark 0.372769 0.100989 3.691 0.000
L1.Tirol 0.508444 0.067567 7.525 0.000
L1.Vorarlberg 0.171100 0.062903 2.720 0.007
L1.Wien -0.198374 0.135329 -1.466 0.143
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.135841 0.160270 0.848 0.397
L1.Burgenland 0.013145 0.084308 0.156 0.876
L1.Kärnten -0.108086 0.068489 -1.578 0.115
L1.Niederösterreich 0.219030 0.193704 1.131 0.258
L1.Oberösterreich 0.024189 0.166741 0.145 0.885
L1.Salzburg 0.218861 0.088576 2.471 0.013
L1.Steiermark 0.122887 0.119958 1.024 0.306
L1.Tirol 0.097978 0.080259 1.221 0.222
L1.Vorarlberg 0.022644 0.074718 0.303 0.762
L1.Wien 0.265184 0.160748 1.650 0.099
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.580946 0.086155 6.743 0.000
L1.Burgenland -0.021829 0.045321 -0.482 0.630
L1.Kärnten -0.002111 0.036817 -0.057 0.954
L1.Niederösterreich -0.035586 0.104128 -0.342 0.733
L1.Oberösterreich 0.286472 0.089633 3.196 0.001
L1.Salzburg 0.016174 0.047615 0.340 0.734
L1.Steiermark 0.012859 0.064484 0.199 0.842
L1.Tirol 0.074678 0.043144 1.731 0.083
L1.Vorarlberg 0.152154 0.040166 3.788 0.000
L1.Wien -0.059898 0.086412 -0.693 0.488
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.153896 0.003208 0.220742 0.258860 0.069876 0.094300 -0.064114 0.165739
Kärnten 0.153896 1.000000 0.018557 0.197874 0.160919 -0.111855 0.170282 0.024031 0.316424
Niederösterreich 0.003208 0.018557 1.000000 0.296450 0.083373 0.229187 0.135398 0.054498 0.364924
Oberösterreich 0.220742 0.197874 0.296450 1.000000 0.293832 0.314408 0.099604 0.079916 0.133414
Salzburg 0.258860 0.160919 0.083373 0.293832 1.000000 0.162093 0.071438 0.072419 -0.012382
Steiermark 0.069876 -0.111855 0.229187 0.314408 0.162093 1.000000 0.115350 0.087921 -0.092436
Tirol 0.094300 0.170282 0.135398 0.099604 0.071438 0.115350 1.000000 0.154244 0.149531
Vorarlberg -0.064114 0.024031 0.054498 0.079916 0.072419 0.087921 0.154244 1.000000 0.078477
Wien 0.165739 0.316424 0.364924 0.133414 -0.012382 -0.092436 0.149531 0.078477 1.000000